{% extends "admin_base.html" %}
{% load humanize %}

{% block container %}
<div class="row">
  <div class="span12">
    <table class="table table-striped table-bordered">
      <thead>
        <tr>
          <th>Invite Code</th>
          <th>Used?</th>
          <th>Created</th>
          <th>Used</th>
          <th>Delete</th>
        </tr>
      </thead>
      <tbody>
        {% for minvite in mass_invites %}
          <tr>
            <td>
              {{minvite.name}} - 
              {{minvite.code}}
              {% if minvite.disabled %} (disabled) {% endif %}
            </td>
            <td>
              {% for user in minvite.users.all %}
                {{user.username}}<br>
              {% empty %}
                No one used this yet
              {% endfor %}
            </td>
            <td>
              {{minvite.created|naturaltime}}
            </td>
            <td>
              {% if minvite.users %}
                {{minvite.modified|naturaltime}}
              {% else %}
                N/A
              {% endif %}
            </td>
            <td>
              <form action="/a/superadmin/invites" method="POST" style="margin: 0">
                {% csrf_token %}
                <input type="hidden" name="command" value="disable">
                <input type="hidden" name="invite" value="{{minvite.pk}}">
                <input type="submit" class="btn btn-danger" value="Disable">
              </form>
            </td>
          </tr>
        {% endfor %}
        {% for invite in invites %}
          <tr>
            <td>{{invite.code}}
            <td>
              {% if invite.used %}
                <a href="/a/superadmin/stream/?username={{invite.user.username}}">
                  {{invite.user}}
                </a>
              {% else %}
                Nope
              {% endif %}
            </td>
            <td>
              {{invite.created|naturaltime}}
              {% if invite.prospective %}
                for <b>{{invite.prospective.name}}</b>
              {% endif %}
            </td>
            <td>
              {% if invite.used %}
                {{invite.modified|naturaltime}}
              {% else %}
                N/A
              {% endif %}
            </td>
            <td>
              <form action="/a/superadmin/invites" method="POST" style="margin: 0">
                {% csrf_token %}
                <input type="hidden" name="command" value="delete">
                <input type="hidden" name="invite" value="{{invite.pk}}">
                <input type="submit" class="btn btn-danger" value="Delete">
              </form>
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
    <form action="/a/superadmin/invites" method="POST">
      {% csrf_token %}
      <input type="hidden" name="command" value="new_invite">
      <input type="submit" class="btn btn-primary" value="New Invite">
    </form>
    <form action="/a/superadmin/invites" method="POST">
      {% csrf_token %}
      <input type="hidden" name="command" value="new_mass_invite">
      <input type="text" name="invite_name" placeholder="Invite name">
      <input type="submit" class="btn btn-primary" value="New Mass Invite">
    </form>
  </div>
</div>
{% endblock container %}